package com.mk.util;

import org.osgl.$;

import java.util.List;
import java.util.Map;

@SuppressWarnings("all")
public class MapUtil extends cn.hutool.core.map.MapUtil {
    /**
     * 支持key {emplooy:{name:"cc"}}  emplooy.name
     *
     * @param map
     * @param key
     * @param defaultValue
     * @return
     */
    public static <T> T getDg(Map map, String key, T defaultValue) {
        String[] prem = key.split("\\.");
        Object o = null;
        for (String keyElement : prem) {
            o = map.get(keyElement);
            if (o instanceof Map)
                map = (Map) o;
            else break;
        }
        return (T) $.ifNullThen(o, defaultValue);
    }

    public static <T> List<T> getList(Map map, String key) {
        if (map.containsKey(key)) {
            return (List<T>) map.get(key);
        }
        return null;
    }

    public static <T, O> Map<T, O> getMap(Map map, String key) {
        if (map.containsKey(key)) {
            return (Map<T, O>) map.get(key);
        }
        return null;
    }

    public static <T> T get(Map map, String key) {
        if (map.containsKey(key)) {
            return (T) map.get(key);
        }
        return null;
    }

    public static <T> T get(Map map, String key, T def) {
        if (map.containsKey(key)) {
            return (T) map.get(key);
        }
        return def;
    }
}
